package com.xoa.service.workflow.flowModelAssociationSet.impl;


import com.xoa.dao.WFE.WFEFlowRunPrcsMapper;
import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.fixAssets.EduFixAssetsMapper;
import com.xoa.dao.hr.HrStaffContractMapper;
import com.xoa.dao.hr.HrStaffInfoMapper;
import com.xoa.dao.users.UserPrivMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.dao.workflow.*;
import com.xoa.model.department.Department;
import com.xoa.model.fixAssets.EduFixAssets;
import com.xoa.model.hr.HrStaffInfo;
import com.xoa.model.users.UserPriv;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.*;
import com.xoa.service.users.UsersService;
import com.xoa.service.workflow.flowModelAssociationSet.FlowAssociationSetService;
import com.xoa.util.ToJson;
import com.xoa.util.common.StringUtils;
import com.xoa.util.page.PageParams;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@Service

public class FlowAssociationSetServiceImpl implements FlowAssociationSetService {

    @Resource
    FlowAssociationSetMapper flowAssociationSetMapper;


    @Resource
    FlowRunPrcsMapper flowRunPrcsMapper;

    @Resource
    FlowTypeModelMapper flowTypeModelMapper;
    @Resource
    WFEFlowRunPrcsMapper wfeFlowRunPrcsMapper;

    @Resource
    UsersService usersService;

    @Resource
    UsersMapper usersMapper;

    @Resource
    FlowProcessMapper flowProcessMapper;

    @Resource
    HrStaffInfoMapper hrStaffInfoMapper;

    @Resource
    EduFixAssetsMapper eduFixAssetsMapper;

    @Resource
    HrStaffContractMapper hrStaffContractMapper;

    @Resource
    DepartmentMapper departmentMapper;

    @Resource
    UserPrivMapper userPrivMapper;

    @Resource
    FlowRunMapper flowRunMapper;


    //新建流程模块关联应用设置wym
    @Override
    public ToJson<FlowRelation> newFlowModelAssociationSet(Integer flowRefNo, Integer flowId, String  flowRelName, Integer  relationType, String  relationFlowId, Integer relationStatus, Integer  flowRange, String  timeRange, Integer  dataDirection, String flowRelDesc, String mapping, String  mappingDesc) {
        ToJson<FlowRelation> json = new ToJson<FlowRelation>(1, "err");
        try{
            Map maps = new HashMap();
            maps.put("flowId",flowId);
            maps.put("relationType",relationType);
            if(relationType ==2){
                maps.put("relationFlowId",relationFlowId);
            }
            List<FlowRelation> flowRelationList = flowAssociationSetMapper.queryFlowModelAssociationSet(maps);
            if(flowRelationList.size()>0){
                //查询流程和模块是否存在
                if(relationType==2){//流程存在
                    json.setFlag(1);
                    json.setMsg("该关联流程已存在");
                    return json;
                }else{//模块已存在则更新
                    maps.put("relationFlowId",relationFlowId);
                    maps.put("flowRelId",flowRelationList.get(0).getFlowRelId());
                    maps.put("mapping",mapping);
                    maps.put("mappingDesc",mappingDesc);
                    int i = flowAssociationSetMapper.editFlowModelAssociationSet(maps);
                    if(i>0){
                        json.setFlag(0);
                        json.setMsg("修改成功");
                        return json;
                    }
                }
            }else{
                Map <String,Object>map = new HashMap<String,Object>();
                int count =0;
                map.put("flowId",flowId);
                map.put("flowRefNo",flowRefNo);
                map.put("flowRelName",flowRelName);
                map.put("relationType",relationType) ;
                map.put("relationFlowId",relationFlowId);
                map.put("relationStatus",relationStatus);
                map.put("flowRange",flowRange);
                map.put("timeRange",timeRange);
                map.put("dataDirection",dataDirection);
                map.put("flowRelDesc",flowRelDesc);
                map.put("mapping",mapping);
                map.put("mappingDesc",mappingDesc);

                count = flowAssociationSetMapper.newModelAssociationSet(map);
                if(count>0){
                    json.setMsg("success");
                    json.setFlag(0);
                }
            }

        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }
    //查询流程模块关联
    public ToJson<FlowRelation> queryFlowModelAssociationSet(Integer pageSize, Integer page, Boolean useFlag,Integer flowId) {
        ToJson<FlowRelation> json = new ToJson<FlowRelation>(1, "err");
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            Map<String,List<FlowRelation>> map1=new HashMap<>();
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(true);
            map.put("page", pageParams);

            //卡片
            map.put("flowId",flowId);
            map.put("relationType",1);
            List<FlowRelation> flowRelationsList1 = flowAssociationSetMapper.queryFlowModelAssociationSetByType(map);
            for (FlowRelation flowRelation:flowRelationsList1) {
                //制度
                int i = flowRelation.getRelationFlowId().indexOf("4,");
                if (i>-1){
                    String mapping=flowRelation.getMapping();
                    int i1 = mapping.indexOf("4-");
                    //最后
                    String substring = mapping.substring(i1, mapping.length());
                    int i2 = substring.indexOf("|");
                    if (i2>-1){
                        String substring1 = substring.substring(0, i2);
                        int i3 = substring1.indexOf("-");
                        String substring2 = substring1.substring(i3+1, substring1.length() - 1);
                        //flowRelation.setInstitutionContents(institutionContentServer.findContentIds(substring2));
                    }

                }
            }
            map1.put("card",flowRelationsList1);

            //流程
            map.clear();
            map.put("flowId",flowId);
            map.put("relationType",2);
            List<FlowRelation> flowRelationsList2=flowAssociationSetMapper.queryFlowModelAssociationSetByType(map);
            for(FlowRelation flowRelation:flowRelationsList2){
                FlowTypeModel flowTypeModel = flowTypeModelMapper.queryOneObject(Integer.valueOf(flowRelation.getRelationFlowId()));
                flowRelation.setRelationFlowName(flowTypeModel.getFlowName());
            }
            map1.put("flow",flowRelationsList2);

            json.setTotleNum(pageParams.getTotal());
            json.setObject(map1);
            json.setMsg("success");
            json.setFlag(0);

        }catch(Exception e){
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }
    //编辑流程模块关联
    @Override
    public ToJson<FlowRelation> editFlowModelAssociationSet(Integer flowRelId, Integer flowRefNo, Integer flowId, String  flowRelName, Integer  relationType, String  relationFlowId, Integer relationStatus, Integer  flowRange, String  timeRange, Integer  dataDirection, String flowRelDesc, String mapping, String  mappingDesc) {
        ToJson<FlowRelation> json = new ToJson<FlowRelation>(1, "err");
        try {
            Map <String,Object>map = new HashMap<String,Object>();
            int count =0;
            //处理mapping映射关系
            //如果插件为空说明是流程关联
            map.put("flowRelId",flowRelId);
            map.put("flowId",flowId);
            map.put("flowRefNo",flowRefNo);
            map.put("flowRelName",flowRelName);
            map.put("relationType",relationType) ;
            map.put("relationFlowId",relationFlowId);
            map.put("relationStatus",relationStatus);
            map.put("timeRange",timeRange);
            map.put("dataDirection",dataDirection);
            map.put("flowRelDesc",flowRelDesc);
            map.put("mapping",mapping);
            map.put("mappingDesc",mappingDesc);
            map.put("flowRange",flowRange);
            count = flowAssociationSetMapper.editFlowModelAssociationSet(map);
            if(count>0){
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }
    //删除流程模块关联应用
    @Override
    public ToJson<FlowRelation> deleteFlowModelAssociationSet(Integer id) {
        ToJson<FlowRelation> json = new ToJson<FlowRelation>(1, "err");
        try {
            int count = flowAssociationSetMapper.deleteFlowModelAssociationSet(id);
            if(count>0){
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public ToJson<FlowRelation> queryModelAssociationField(String tableName) {
        ToJson<FlowRelation> json = new ToJson<FlowRelation>(1, "err");
        try {
            if("eduFixAssets".equals(tableName)){
                tableName = "edu_fixed_assets_mangement";
            }
            List<FlowRelation> flowRelations = flowAssociationSetMapper.queryModelAssociationField(tableName);
            json.setObj(flowRelations);
            json.setMsg("success");
            json.setFlag(0);
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    //通过flowID查询关联设置满足的流程
    @Override
    public ToJson<Map<String,Object>> queryFlowAssociationFlowRunPrcs(Integer flowId,String type) {
        ToJson<Map<String,Object>> json = new  ToJson<Map<String,Object>>(1, "err");
        try {
            //查询当前流程满足的关联设置
            List<FlowRelation> flowRelations = flowAssociationSetMapper.queryFlowAssociationSet(flowId);
            List<Map<String,Object>> flowRunPrcsMap = new ArrayList<Map<String,Object>>();

            if(flowRelations.size()>0){
                for(FlowRelation flowRelation :flowRelations ){
                    //区分关联流程和关联模块
                    if(flowRelation.getRelationType()==2){//关联流程
                        //  `TIME_RANGE` 时间范围(上月1、上季度2、上年度3、本月4、本季度5、本年6)',
                        String timeRange = flowRelation.getTimeRange();//关联的时间范围
                        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
                        SimpleDateFormat f=new SimpleDateFormat("yyyy");
                        Date date = new Date();
                        String syd = "";//上月第一天
                        String syz ="";//上月最后一天
                        switch (timeRange){
                            case "1":
                                Calendar calendar=Calendar.getInstance();
                                calendar.add(Calendar.MONTH, -1);
                                calendar.set(Calendar.DAY_OF_MONTH, 1);
                           //   上个月第一天：
                                syd =  format.format(calendar.getTime())+" 00:00:00";
                                //System.out.println("上个月第一天："+sdf.format(calendar.getTime()));
                                calendar.setTime(new Date());
                                calendar.add(Calendar.MONTH, -1);
                                calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                                syz = format.format(calendar.getTime())+" 23:59:59";
                                break;
                            case "2":
                                Calendar startCalendar = Calendar.getInstance();
                                startCalendar.set(Calendar.MONTH, ((int) startCalendar.get(Calendar.MONTH) / 3 - 1) * 3);
                                startCalendar.set(Calendar.DAY_OF_MONTH, 1);
                                syd = format.format(startCalendar.getTime())+" 00:00:00";

                                Calendar endCalendar = Calendar.getInstance();
                                endCalendar.set(Calendar.MONTH, ((int) endCalendar.get(Calendar.MONTH) / 3 - 1) * 3 + 2);
                                endCalendar.set(Calendar.DAY_OF_MONTH, endCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
                                syz = format.format(endCalendar.getTime())+" 23:59:59";
                                break;
                            case "3":
                                //上年度第一天
                                int year = Integer.valueOf(f.format(date));
                                year = year-1;
                                syd = year+"-01-01 00:00:00";
                                syz = year+"-12-31 23:59:59";
                                break;
                            case "4":
                                //本月第一天
                                //获取前月的第一天
                                Calendar c = Calendar.getInstance();
                                c.add(Calendar.MONTH, 0);
                                c.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
                                String first = format.format(c.getTime());
                                syd = format.format(c.getTime())+" 00:00:00";
                                //本月最后一天
                                c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
                                syz = format.format(c.getTime())+" 23:59:59";
                                break;
                            case "5":
                                Calendar calendar1 = Calendar.getInstance();
                                calendar1.set(Calendar.MONTH, ((int) calendar1.get(Calendar.MONTH) / 3) * 3);
                                calendar1.set(Calendar.DAY_OF_MONTH, 1);
                                syd = calendar1.getTime()+" 00:00:00";
                                calendar1.set(Calendar.MONTH, ((int) calendar1.get(Calendar.MONTH) / 3) * 3 + 2);
                                calendar1.set(Calendar.DAY_OF_MONTH, calendar1.getActualMaximum(Calendar.DAY_OF_MONTH));
                                syz =calendar1.getTime()+" 23:59:59";
                                break;
                            case "6"://本年第一天，本年最后一天
                                Calendar currCal=Calendar.getInstance();
                                int currentYear = currCal.get(Calendar.YEAR);
                                syd = currentYear+"-01-01 00:00:00";
                                syz = currentYear+"-12-31 23:59:59";
                                break;
                        }
                        Map<String,Object>map = new HashMap<String,Object>();
                        //区分该流程关联
                        Map<String,Object>map1 = new HashMap<String,Object>();
                        //根据该流程的id查出流程名称
                        long startTime = System.currentTimeMillis();
                        FlowTypeModel flowTypeModel = flowTypeModelMapper.queryOneObject(Integer.valueOf(flowRelation.getRelationFlowId()));
                        long endTime = System.currentTimeMillis();
                       // System.out.println("根据流程ID-----SQL查询耗时为： " + ( endTime - startTime ));
                        //获取当前流程号与关联流程号拼接表名
                        map.put("currentTableName","FLOW_DATA_"+  flowRelation.getFlowId());
                        //map.put("queryData","FLOW_DATA_"+ flowRelation.getRelationFlowId()+".RUN_ID");
                        map.put("queryData","guan"+".RUN_ID");//防止不能查询本流程关联本流程
                        map.put("relationTableName","FLOW_DATA_"+ flowRelation.getRelationFlowId());
                        String mappingSqlStr = "";
                        //将每一关联设置中的映射关系取出
                        String mappingStr =  flowRelation.getMapping();
                        String[] mappingSplitArray = mappingStr.split("\\|");
                        for(int i=0;i<mappingSplitArray.length;i++){
                            String mappingTempArray = mappingSplitArray[i];
                            String[] mappings = mappingTempArray.split("=>");
                            for(int j=0;j<mappings.length;j++){
                                if(j==0){
                                    //mappingSqlStr +="FLOW_DATA_"+  flowRelation.getFlowId()+"."+mappings[j]+"=";//现在的流程data
                                    if(!StringUtils.checkNull(mappings[j])){
                                        mappingSqlStr +="xian"+"."+mappings[j]+"=";//现在的流程data   防止不能查询本流程关联本流程
                                    }
                                }else{
                                    //mappingSqlStr +="FLOW_DATA_"+ flowRelation.getRelationFlowId()+"."+mappings[j]+" AND ";//关联的流程data
                                    mappingSqlStr +="guan"+"."+mappings[j]+" AND ";//关联的流程data   防止不能查询本流程关联本流程
                                }
                            }
                        }
                        // mappingSqlStr += "FLOW_DATA_"+  flowRelation.getRelationFlowId()+".begin_time > "+syd +" AND "+"FLOW_DATA_"+flowRelation.getRelationFlowId()+".begin_time <= "+syz;
                        //mappingSqlStr += "flow_run.run_id="+"FLOW_DATA_"+  flowRelation.getFlowId()+".run_id";
                        mappingSqlStr += "flow_run.run_id="+"xian"+".run_id";//防止不能查询本流程关联本流程
                        //截取最后“AND"
                        //mappingSqlStr = mappingSqlStr.substring(0,mappingSqlStr.length()-4);
                        map.put("where",mappingSqlStr);
                        map.put("startTime",syd);
                        map.put("endTime",syz);
                        if(1==flowRelation.getFlowRange()){//经办范围
                            map.put("opFlag",flowRelation.getFlowRange());
                        }
                        if("1".equals(type)){//分页
                            PageParams pageParams = new PageParams();
                            pageParams.setPage(1);
                            pageParams.setPageSize(5);
                            pageParams.setUseFlag(true);
                            map.put("page", pageParams);
                        }
                        try{
                            long startTime1 = System.currentTimeMillis();
                            List<Integer>runIdList = flowAssociationSetMapper.queryFlowDataRunId(map);
                            long endTime1 = System.currentTimeMillis();
                            //System.out.println("根据条件查询对应流水号ID-----SQL查询耗时为： " + ( endTime1 - startTime1 ));
                            List<FlowRunPrcs> flowRunPrcsList = new ArrayList<FlowRunPrcs>();
                            //查询符合关联条件的流水号
                            if(runIdList.size()>0){
                                for(int i=0;i<runIdList.size();i++){
                                    //查询当前流水号对应的flow_run_prcs
                                    List<FlowRunPrcs> flowRunPrcs = wfeFlowRunPrcsMapper.selectPrcsId1(runIdList.get(i));
                                    if(flowRunPrcs.size()>0){
                                        for(FlowRunPrcs flowRunPrcs1:flowRunPrcs){
                                            List<FlowProcess> flowProcess = flowProcessMapper.findFlowId(Integer.valueOf(flowRelation.getRelationFlowId()));
                                            flowRunPrcs1.setFlowId(flowProcess.get(0).getFlowId());
                                            flowRunPrcs1.setFlowName(flowProcess.get(0).getFlowName());
                                            FlowRun flowRun = flowRunMapper.find(runIdList.get(i));
                                            Users users = usersMapper.findUsersByuserId(flowRun.getBeginUser());
                                            flowRunPrcs1.setUserName(users.getUserName());
                                        }
                                        flowRunPrcsList.add(flowRunPrcs.get(0));
                                    }
                                }
                                map1.put(flowTypeModel.getFlowName(),flowRunPrcsList);
                                flowRunPrcsMap.add(map1);
                            }
                        }catch (Exception e){
                            //可能关联的该流程没有操作的数据库表
                            continue;
                        }
                    }else{
                        //如果是模块关联

                    }
                }
            }
            json.setMsg("success");
            json.setFlag(0);
            json.setObj(flowRunPrcsMap);
        }catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public List<FlowRelation> queryFlowAssociationSet(Integer flowId) {
        return flowAssociationSetMapper.queryFlowAssociationSet(flowId);
    }

    @Override
    public ToJson<FlowRelation> newModelAssociationSet(Integer flowId, Integer relationType,String relationFlowId) {
        ToJson<FlowRelation> json = new ToJson<FlowRelation>(1, "err");
        try {
            Map map = new HashMap();
            map.put("flowId",flowId);
            map.put("flowRefNo",0);
            map.put("flowRelName","");
            map.put("relationType",relationType) ;
            map.put("relationFlowId",relationFlowId);
            map.put("relationStatus",1);
            map.put("flowRange",0);
            map.put("timeRange",6);
            map.put("dataDirection",0);
            map.put("flowRelDesc","");
            map.put("mapping","");
            map.put("mappingDesc","");
            int i = flowAssociationSetMapper.newFlowModelAssociationSet(map);
            if(i>0){
                json.setMsg("success");
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public ToJson<FlowRelation> getFlowRunInfo(Integer flowId, Integer runId, Integer relationType,String printModel,String attributesStr) {
        ToJson<FlowRelation> toJson = new ToJson<FlowRelation>();
        Map map = new HashMap();
        map.put("flowId",flowId);
        map.put("runId",runId);
        map.put("relationType",relationType);
        try{
            String model1="";
            String model2="";
            String model3="";
            //1.获取需要展示的信息（1人事档案2合同管理3固定资产）
            List<FlowRelation> flowRelationWithBLOBs = flowAssociationSetMapper.queryModelAssociationRelation(map);
            for (FlowRelation flowRelation : flowRelationWithBLOBs) {
                String mapping = flowRelation.getMapping();
                String[] mappingStr = mapping.split("\\|");
                for(int i=0;i<mappingStr.length;i++){
                    String mappingI = mappingStr[i];//每一个模块的对应关系
                    String[] mappingIJ = mappingI.split("-");
                    Map mappingMap = new HashMap();
                    mappingMap.put("table","FLOW_DATA_"+flowRelation.getFlowId());
                    String where = "RUN_ID="+runId;
                    mappingMap.put("where",where);
                    List flowRelationList = new ArrayList();
                    Users users = new Users();
                    String userName ="";
                   switch (mappingIJ[0]){
                       case "1":
                           if(mappingIJ.length==2){
                               model1 = mappingIJ[1];
                               mappingMap.put("result",model1);
                               userName = flowAssociationSetMapper.queryModelTableResult(mappingMap);
                               if(!"".equals(userName)&&userName!=null){
                                   users = usersMapper.getUsersByname(userName);
                               }
                               if("".equals(users.getUserId())||users.getUserId()==null){//该用户不存在
                                   users = usersMapper.findUsersByuserId(flowRelation.getBeginUser());
                               }else{
                                   UserPriv userPriv = userPrivMapper.selectByPrimaryKey(users.getUserPriv());
                                   Department department = departmentMapper.getDeptById(users.getDeptId());
                                   users.setUserNameIndex(userPriv.getPrivName());
                                   users.setDep(department);
                                   flowRelationList.add(users);
                                   flowRelation.setUsers(flowRelationList);
                               }
                           }
                           break;
                       case "2":
                           if(mappingIJ.length==2){
                               model2 = mappingIJ[1];
                               mappingMap.put("result",model2);
                               userName = flowAssociationSetMapper.queryModelTableResult(mappingMap);
                               users = new Users();
                               if(!"".equals(userName)&&userName!=null){
                                   users = usersMapper.getUsersByname(userName);
                               }
                               if("".equals(users.getUserId())||users.getUserId()==null){//该用户不存在
                                   users = usersMapper.findUsersByuserId(flowRelation.getBeginUser());
                               }else{
                                   Department department = departmentMapper.getDeptById(users.getDeptId());
                                   UserPriv userPriv = userPrivMapper.selectByPrimaryKey(users.getUserPriv());
                                   List<HrStaffInfo> hrStaffInfos = hrStaffInfoMapper.selectInfoByCreateUserId(users.getUserId());
                                   if(hrStaffInfos.size()>0){
                                       hrStaffInfos.get(0).setDeptName(department.getDeptName());
                                       hrStaffInfos.get(0).setUserPriv(userPriv.getPrivName());
                                       flowRelation.setHrStaffInfo(hrStaffInfos);
                                   }

                               }
                           }

                           break;
                       case "3"://固定资产
                           if(mappingIJ.length==2){
                               model3 =mappingIJ[1];
                               int y=0;
                               mappingMap.put("result",model3);
                               String assIdStr="";
                               if(!"".equals(printModel)&&printModel!=null&&!"".equals(attributesStr)&&attributesStr!=null){
                                   //卡片编号`固定资产名称`规格`调出单位`调入单位`备注`
                                    String[] lvTitle = printModel.split("`");
                                    for(int j=0;j<lvTitle.length;j++){
                                        String contentTemp = lvTitle[j];
                                        if(contentTemp.contains("编号")){
                                             y =j;
                                            break;
                                        }
                                    }//取出多少位
  //02283`美的空调`KFR-35G/BP2DN1Y-YA301(B3)`深潜号`聚力号`未拆包`02284`美的空调`KFR-35G/BP2DN1Y-YA301(B3)`深潜号`聚力号`未拆包`
                                   String assId = flowAssociationSetMapper.queryModelTableResult(mappingMap);
                                   String[] assIdArray = assId.split("\r\n");
                                   String[] zz =null;
                                   for(int z=0;z<assIdArray.length;z++){
                                       String assI = assIdArray[z];
                                       zz = assI.split("`");
                                       if(zz.length==0){
                                           break;
                                       }
                                       assIdStr+=zz[y]+"|";
                                   }
                                   String[] assIds=null;
                                   if(!"".equals(assIdStr)&&assIdStr!=null){
                                       assIds = assIdStr.split("\\|");
                                   }
                                   for(String s:assIds){
                                      EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(s);
                                       String keeper = eduFixAssets.getKeeper();
                                       if(!"".equals(keeper)&&keeper!=null){
                                           String[] keeperStr = keeper.split(",");
                                           Users u = usersMapper.getUserByUid(Integer.valueOf(keeperStr[0])) ;
                                           eduFixAssets.setKeeperName(u.getUserName());
                                       }
                                       Integer typeId = eduFixAssets.getTypeId();
                                       String typeName = eduFixAssetsMapper.getTypeIdTypeName(String.valueOf(typeId));
                                       eduFixAssets.setTypeName(typeName);
                                       if(eduFixAssets!=null){
                                           flowRelationList.add(eduFixAssets);
                                       }
                                   }
                                   flowRelation.setEduFixAssets(flowRelationList);
                               }else{
                                   //固定资产编号
                                   String assId = flowAssociationSetMapper.queryModelTableResult(mappingMap);
                                   EduFixAssets eduFixAssets = eduFixAssetsMapper.selFixAssetsById(assId);
                                   if(eduFixAssets!=null){
                                       flowRelationList.add(eduFixAssets);
                                       flowRelation.setEduFixAssets(flowRelationList);
                                   }else{
                                       Map<String, Object> map1 = new HashMap<String, Object>();
                                       map1.put("creater", flowRelation.getBeginUser());
                                       map1.put("isAssets", 1);
                                       List<EduFixAssets> s = eduFixAssetsMapper.selectByCreater(map);
                                       //显示创建的固定资产
                                       flowRelation.setEduFixAssets(s);
                                   }
                               }

                           }
                           break;
                       case "4": //制度管理
                           if(mappingIJ.length==2){
                              // flowRelation.setInstitutionContents(institutionContentServer.findContentIds(mappingIJ[1]));
                           }
                           break;
                   }
                }
            }
            toJson.setMsg("success");
            toJson.setFlag(1);
            toJson.setObject(flowRelationWithBLOBs);
        }catch (Exception e){
            e.printStackTrace();
            toJson.setMsg("erro");
            toJson.setFlag(0);
        }
        return toJson;
    }

}